package com.bdqn.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bdqn.base.R;
import com.bdqn.base.logger.WebLogger;
import com.bdqn.pojo.ShopStore;
import com.bdqn.service.ShopStoreService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 店铺
 *
 * @author lilibo
 * @date 2021/10/01
 */
@Api(tags="店铺接口")
@RestController
@RequestMapping("/shopstore")
public class ShopStoreController {

    @Autowired
    private ShopStoreService shopStoreService;

    /**
     * 新增店铺记录
     *
     * @param shopStore
     * @return R
     */
    @ApiOperation("新增店铺记录")
    @WebLogger("新增店铺记录")
    @PostMapping("/add")
    public R save(@ApiParam("店铺对象") @RequestBody ShopStore shopStore) {
        return new R<>(shopStoreService.save(shopStore));
    }

    /**
     * 修改店铺记录
     *
     * @param shopStore
     * @return R
     */
    @ApiOperation("修改店铺记录")
    @WebLogger("修改店铺记录")
    @PostMapping("/update")
    public R update(@ApiParam("店铺对象") @RequestBody ShopStore shopStore) {
        return new R<>(shopStoreService.updateById(shopStore));
    }

    /**
     * 通过id删除一条店铺记录
     *
     * @param id
     * @return R
     */
    @ApiOperation("通过id删除一条店铺记录")
    @WebLogger("通过id删除一条店铺记录")
    @PostMapping("/delete")
    public R removeById(@ApiParam("店铺id") Integer id) {
        return new R<>(shopStoreService.removeById(id));
    }

    /**
     * 通过多个id批量删除店铺记录
     *
     * @param ids
     * @return R
     */
    @ApiOperation("通过多个id批量删除店铺记录")
    @WebLogger("通过多个id批量删除店铺记录")
    @PostMapping("/remove")
    public R removeByIds(@ApiParam("店铺id集合") @RequestBody List<Integer> ids) {
        return new R<>(shopStoreService.removeByIds(ids));
    }

    /**
     * 通过id查询单条店铺记录
     *
     * @param id
     * @return R
     */
    @ApiOperation("通过id查询单条店铺记录")
    @WebLogger("通过id查询单条店铺记录")
    @GetMapping("/{id}")
    public R<ShopStore> getById(@ApiParam("店铺id") @PathVariable Integer id) {
        return new R<>(shopStoreService.getById(id));
    }

    /**
     * 通过店铺信息查询店铺记录
     *
     * @param shopStore 店铺信息对象
     * @return R
     */
    @ApiOperation("通过店铺信息查询店铺记录")
    @WebLogger("通过店铺信息查询店铺记录")
    @GetMapping("/list")
    public R<List<ShopStore>> getList(@ApiParam("查询的店铺对象") ShopStore shopStore) {
        return new R<>(shopStoreService.getList(shopStore));
    }

    /**
     * 分页查询店铺
     *
     * @param pageNo 当前页
     * @param pageSize 每页条数
     * @param shopStore 店铺
     * @return
     */
    @ApiOperation("分页查询店铺")
    @WebLogger("分页查询店铺")
    @GetMapping("/page")
    public R<IPage<ShopStore>> getPage(@ApiParam("当前页") @RequestParam(required = false, defaultValue = "1")  Long pageNo, @ApiParam("每页条数") @RequestParam(required = false, defaultValue = "10") Long pageSize, @ApiParam("查询的店铺对象") ShopStore shopStore) {
        return new R<>(shopStoreService.getPage(new Page<>(pageNo, pageSize), shopStore));
    }

    /**
     * 分页查询店铺数据
     *
     * @param pageNo 当前页
     * @param pageSize 每页条数
     * @param shopStore 店铺
     * @return 返回对象中的count为数据总量
     */
    @ApiOperation("分页查询店铺数据")
    @WebLogger("分页查询店铺数据")
    @GetMapping("/pagelist")
    public R<List<ShopStore>> getPageList(@ApiParam("当前页") @RequestParam(required = false, defaultValue = "1")  Long pageNo, @ApiParam("每页条数") @RequestParam(required = false, defaultValue = "10") Long pageSize, @ApiParam("查询的店铺对象") ShopStore shopStore) {
        IPage<ShopStore> page = shopStoreService.getPage(new Page<>(pageNo, pageSize), shopStore);
        return new R<>(page.getRecords(), page.getTotal());
    }

}
